<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript" src="../js/axios.min.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="../css/animate.css">
</head>

<body>
    <div id="app" class="container">
        <button class="btn btn-primary" @click="clickMethod">点击</button>
        <p ref="hkp">先整他一个亿</p>

        <hr>

        <comp ref="hkcomp"></comp>

    </div>

    <template id="temp1">
        <h3>我是组件中的h3</h3>
    </template>

    <script>
        var comp = {
            template: '#temp1',
            data() {
                return {
                    msg: 'hello world'
                }
            },
            methods: {
                func() {
                    alert("触发组件的方法");
                }
            }
        }

        var vm = new Vue({
            el: '#app',
            data: {},
            methods: {
                clickMethod() {
                    // alert(this.$refs.hkp.innerText)
                    this.$refs.hkcomp.func()
                }
            },
            components: {
                comp
            }
        });
    </script>
</body>

</html>